package jdk5.concurrent;

import java.net.Socket;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.BufferedInputStream;


public class Worker implements Runnable{
          private Socket s;
       
         public Worker(Socket s){ this.s = s;}

         public void run(){
              try{
                         BufferedReader br = new BufferedReader(
                                    new InputStreamReader(s.getInputStream()));
                         BufferedOutputStream bos = new BufferedOutputStream(
                                    s.getOutputStream());
                         String fileName = br.readLine();
                         BufferedInputStream bis = new BufferedInputStream(
                                    new FileInputStream(fileName));
                         byte[] buf = new byte[2048];
                         int len = 0;
                         while((len = bis.read(buf)) > 0)
                             bos.write(buf, 0, len);
                        bos.flush();
              }catch(IOException ioe){
                      ioe.printStackTrace();
             }finally{
                    try{ s.close(); } catch(Exception e){}
            }
        }
}